package tech.aistar.controller;

import tech.aistar.service.IPhoneService;
import tech.aistar.service.impl.PhoneServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/9/6
 * @Version: 1.0
 */
@WebServlet(urlPatterns = "/phone/del/*")
public class PhoneDelAction extends HttpServlet {
    private IPhoneService phoneService = new PhoneServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String pathInfo = req.getPathInfo();
        switch (pathInfo){
            case "/one":
                //删除单个的
                String id = req.getParameter("id");
                phoneService.delById(Integer.valueOf(id));
            case "/any":
                //获取多个的
                String[] ids = req.getParameterValues("id");
                for (String s : ids) {
                    phoneService.delById(Integer.valueOf(s));
                }
                break;

        }
        resp.sendRedirect(req.getContextPath()+"/phone/index");

    }
}
